package com.logos.musicframe.adapter;

import com.logos.musicframe.entity.FileInfo;
import com.logos.musicframe.utils.MinioUtil;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

import java.io.InputStream;
import java.util.List;

/**
 * @author logos
 * date 2025/6/04 21:26
 * @version v1.0
 * @Package com.logos.musicframe.adapter
 */
public class MinioStorageAdapter implements StorageAdapter {

    @Autowired
    private MinioUtil minioUtil;

    /**
     * minioUrl
     */
    @Value("${minio.url}")
    private String url;

    @Override
    @SneakyThrows
    public void createBucket(String bucketName) {
        minioUtil.createBucket(bucketName);
    }

    @Override
    @SneakyThrows
    public String uploadFile(byte[] fileBytes, String bucket, String objectName, String originalFilename) {
        minioUtil.createBucket(bucket);
        return minioUtil.uploadFile(fileBytes, bucket,originalFilename);
    }



    @Override
    @SneakyThrows
    public List<String> getAllBucket() {
        return minioUtil.getAllBucket();
    }

    @Override
    @SneakyThrows
    public List<FileInfo> getAllFile(String bucket) {
        return minioUtil.getAllFile(bucket);
    }

    @Override
    @SneakyThrows
    public InputStream downLoad(String bucket, String objectName) {
        return minioUtil.downLoad(bucket, objectName);
    }

    @Override
    @SneakyThrows
    public void deleteBucket(String bucket) {
        minioUtil.deleteBucket(bucket);
    }

    @Override
    @SneakyThrows
    public void deleteObject(String bucket, String objectName) {
        minioUtil.deleteObject(bucket, objectName);
    }

    @Override
    @SneakyThrows
    public String getPreviewFileUrl(String bucketName, String objectName) {
        return url + "/" + bucketName + "/" + objectName;
    }

    @Override
    @SneakyThrows
    public String getUrl(String bucket, String objectName) {
        return url + "/" + bucket + "/" + objectName;
    }
}
